<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>内部合同产品信息管理</title>
<meta name="decorator" content="default" />
<script type="text/javascript">
	$(document)
			.ready(
					function() {
						//全选
						$("#checkAll").click(function() {
									$('input[name="id"]').attr("checked",this.checked);
								});
						var $subBox = $("input[name='id']");
						$subBox.click(function() {
									$("#checkAll").attr("checked",$subBox.length == $("input[name='id']:checked").length ? true : false);
						});

					});
	//分页
	function page(n, s) {
		$("#pageNo").val(n);
		$("#pageSize").val(s);
		$("#searchForm").attr("action", "${ctx}/pro/virtualDetail/list");
		$("#searchForm").submit();
		return false;
	}

	//删除
	function deleteData() {
			var $id = $("input[name='id']:checked");
			var ids = new Array();
			var j = 0;
			if ($id.val() != null && $id.val() != '') {
				var submit = function (v, h, f) {
				    if (v == 'ok'){
				        $id.each(function(i, info) {
							ids[j] = info.value;
							j++;
						});
				        resetTip();
						location.href = "${ctx}/pro/virtualDetail/deleteData?ids="+ ids;
				    }else if (v == 'cancel'){
				    	return true;
				    }
				};
				$.jBox.confirm("确认删除此信息吗？", "提示", submit);
			}else{
				jBox.tip("请勾选需要删除的数据！");
			}
	}

	
	//显示查看框
	 function show(){
		 $.jBox($("#see").html(), {
				id: 'selectJBox', 
				title : "选择产品",
				width : 'auto',
				height : "auto",
				buttons : {"关闭" : true },
				submit : function(v, h, f) {
		  			if (v == false) {
		  				return true;
		  			}
		  		}
		 });
	 }
	
	
	 /**
	  * 全局变量
	  */
	 var pageNoOne;//页码
	 var pageSizeOne;//页码大小
	 var countOne;//总数
	 var cId;//
	//查看
	function see(obj) {
		$("#productInfoTbody").html("");
		cId = $(obj).next().val();
		var newRow = "";
		$("#codes").attr('value',$(obj).parent().parent().children("td:eq(1)").html());
		$("#virtualContractRemarks").attr('value',$(obj).parent().parent().children("td:eq(2)").html());
		var page;
		var virtualDetailList;
		var newRow = '';
		//获取表格中的数据
		$.getJSON("${ctx}/pro/virtualDetail/see", "virtualContract.id=" + cId,
				function(data) {
			$.each(data, function(key, value) {
				if(key == 'page'){
					page = value;
				}else if(key == 'columnList'){
					columnList = value;
				}
			});
			if(typeof(page.list) != "undefined" && typeof(columnList) != "undefined"){
				$.each(page.list, function(i, info) {
					newRow = '<tr>';
					$.each(columnList, function(j, column) {
						if(column.className == 'productInfoName'){
							newRow += '<td>'+info.productName+'</td>';
						}
						if(column.className == 'productInfoProductCode'){
							newRow += '<td>'+info.productCode+'</td>';
						}
						if(column.className == 'productInfoSpecifications'){
							newRow += '<td>'+info.specifications+'</td>';
						}
						if(column.className == 'productInfoBrand'){
							newRow += '<td>'+info.brand+'</td>';
						}
						if(column.className == 'productInfoPackaging'){
							newRow += '<td>'+info.packaging+'</td>';
						}
						if(column.className == 'unitName'){
							newRow += '<td>'+info.unit+'</td>';
						}
						if(column.className == 'supplierName'){
							newRow += '<td>'+info.supplier+'</td>';
						}
						if(column.className == 'noTaxPrice'){
							newRow += '<td>'+info.noTaxPrice+'</td>';
						}
						if(column.className == 'taxPrice'){
							newRow += '<td>'+info.taxPrice+'</td>';
						}
						if(column.className == 'count'){
							newRow += '<td>'+info.count+'</td>';
						}
						if(column.className == 'brandReplace'){
							newRow += '<td>'+info.brandReplace+'</td>';
						}
						if(column.className == 'abnormalProblem'){
							newRow += '<td>'+info.abnormalProblem+'</td>';
						}
						if(column.className == 'executor'){
							newRow += '<td>'+info.executor+'</td>';
						}
						if(column.className == 'enquiryDate'){
							if(typeof(info.enquiryDate) == "undefined"){
								newRow += '<td></td>';
							}else{
								var date =new Date(info.enquiryDate);
								newRow += '<td>'+date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate()+'</td>';
							}
						}
						if(column.className == 'deliveryDate'){
							if(typeof(info. deliveryDate) == "undefined"){
								newRow += '<td></td>';
							}else{
								var date =new Date(info. deliveryDate);
								newRow += '<td>'+date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate()+'</td>';
							}
						}
						if(column.className == 'expirationDate'){
							newRow += '<td>'+info.expirationDate+'</td>';
						}
						if(column.className == 'affirmFlag'){
							if(info.affirmFlag==1){
							newRow += '<td><i class="icon-ok" style="color: red;"></i></td>';
							}else{
								newRow+='<td><i class="icon-remove"></i></td>';
							}
						}
						if(column.className == 'remarks'){
							newRow += '<td>'+info.remarks+'</td>';
						}
					});
					newRow += '</tr>';
					$("#productInfoTbody").append(newRow);
				});
			}
			pageNoOne = page.pageNo;
			pageSizeOne = page.pageSize;
			countOne = page.count;
			$("#clientelePageNo").html(pageNoOne);
			$("#clientelePageSize").html(pageSizeOne);
			$("#clienteleCount").html(countOne);
			if(pageNoOne <= 1){
				$("#clientelePreviousPageLi").attr("class","disabled");
			}
			if(pageNoOne >= countOne/pageSizeOne){
				$("#clienteleNextPageLi").attr("class","disabled");
			}
			//弹出选择框
			show();
		});
	 }
	
	/**
	  * 下一页
	  */
	 $("#clienteleNextPage").live("click",function(){
	 	if(pageNoOne < countOne/pageSizeOne){
	 		$("#productInfoTbody").html("");
	 		var page;
			var virtualDetailList;
			var newRow = '';
			//获取列信息
			$.getJSON("${ctx}/pro/virtualDetail/see", "pageNo="+(pageNoOne+1)+"&virtualContract.id=" + cId, function(data) {
				$.each(data, function(key, value) {
					if(key == 'page'){
						page = value;
					}else if(key == 'columnList'){
						columnList = value;
					}
				});
				if(typeof(page.list) != "undefined" && typeof(columnList) != "undefined"){
					$.each(page.list, function(i, info) {
						newRow = '<tr>';
						$.each(columnList, function(j, column) {
							if(column.className == 'productInfoName'){
								newRow += '<td>'+info.productName+'</td>';
							}
							if(column.className == 'productInfoProductCode'){
								newRow += '<td>'+info.productCode+'</td>';
							}
							if(column.className == 'productInfoSpecifications'){
								newRow += '<td>'+info.specifications+'</td>';
							}
							if(column.className == 'productInfoBrand'){
								newRow += '<td>'+info.brand+'</td>';
							}
							if(column.className == 'productInfoPackaging'){
								newRow += '<td>'+info.packaging+'</td>';
							}
							if(column.className == 'unitName'){
								newRow += '<td>'+info.unit+'</td>';
							}
							if(column.className == 'supplierName'){
								newRow += '<td>'+info.supplier+'</td>';
							}
							if(column.className == 'noTaxPrice'){
								newRow += '<td>'+info.noTaxPrice+'</td>';
							}
							if(column.className == 'taxPrice'){
								newRow += '<td>'+info.taxPrice+'</td>';
							}
							if(column.className == 'count'){
								newRow += '<td>'+info.count+'</td>';
							}
							if(column.className == 'brandReplace'){
								newRow += '<td>'+info.brandReplace+'</td>';
							}
							if(column.className == 'abnormalProblem'){
								newRow += '<td>'+info.abnormalProblem+'</td>';
							}
							if(column.className == 'executor'){
								newRow += '<td>'+info.executor+'</td>';
							}
							if(column.className == 'enquiryDate'){
								if(typeof(info.enquiryDate) == "undefined"){
									newRow += '<td></td>';
								}else{
									var date =new Date(info.enquiryDate);
									newRow += '<td>'+date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate()+'</td>';
								}
							}
						
							if(column.className == 'deliveryDate'){
								if(typeof(info. deliveryDate) == "undefined"){
									newRow += '<td></td>';
								}else{
									var date =new Date(info. deliveryDate);
									newRow += '<td>'+date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate()+'</td>';
								}
							}
							if(column.className == 'expirationDate'){
								newRow += '<td>'+info.expirationDate+'</td>';
							}
							if(column.className == 'remarks'){
								newRow += '<td>'+info.remarks+'</td>';
							}
						});
						newRow += '</tr>';
						$("#productInfoTbody").append(newRow);
					});
				}
				pageNoOne = page.pageNo;
				pageSizeOne = page.pageSize;
				countOne = page.count;
				$("#clientelePageNo").html(pageNoOne);
				$("#clientelePageSize").html(pageSizeOne);
				$("#clienteleCount").html(countOne);
				$("#clientelePreviousPageLi").attr("class","");
				if(pageNoOne <= 1){
					$("#clientelePreviousPageLi").attr("class","disabled");
				}
				if(pageNoOne >= countOne/pageSizeOne){
					$("#clienteleNextPageLi").attr("class","disabled");
				}
				$.jBox.close(selectJBox);
				//弹出选择框
				show();
			});
	 	}
	 });

	 /**
	 * 上一页
	 */
	 $("#clientelePreviousPage").live("click",function(){
	 	if(pageNoOne > 1){
	 		$("#productInfoTbody").html("");
	 		var page;
			var realDetailList;
			var newRow = '';
			//获取列信息
			$.getJSON("${ctx}/pro/virtualDetail/see", "pageNo="+(pageNoOne-1)+"&virtualContract.id=" + cId, function(data) {
				$.each(data, function(key, value) {
					if(key == 'page'){
						page = value;
					}else if(key == 'columnList'){
						columnList = value;
					}
				});
				if(typeof(page.list) != "undefined" && typeof(columnList) != "undefined"){
					$.each(page.list, function(i, info) {
						newRow = '<tr>';
						$.each(columnList, function(j, column) {
							if(column.className == 'productInfoName'){
								newRow += '<td>'+info.productName+'</td>';
							}
							if(column.className == 'productInfoProductCode'){
								newRow += '<td>'+info.productCode+'</td>';
							}
							if(column.className == 'productInfoSpecifications'){
								newRow += '<td>'+info.specifications+'</td>';
							}
							if(column.className == 'productInfoBrand'){
								newRow += '<td>'+info.brand+'</td>';
							}
							if(column.className == 'productInfoPackaging'){
								newRow += '<td>'+info.packaging+'</td>';
							}
							if(column.className == 'unitName'){
								newRow += '<td>'+info.unit+'</td>';
							}
							if(column.className == 'supplierName'){
								newRow += '<td>'+info.supplier+'</td>';
							}
							if(column.className == 'noTaxPrice'){
								newRow += '<td>'+info.noTaxPrice+'</td>';
							}
							if(column.className == 'taxPrice'){
								newRow += '<td>'+info.taxPrice+'</td>';
							}
							if(column.className == 'count'){
								newRow += '<td>'+info.count+'</td>';
							}
							if(column.className == 'brandReplace'){
								newRow += '<td>'+info.brandReplace+'</td>';
							}
							if(column.className == 'abnormalProblem'){
								newRow += '<td>'+info.abnormalProblem+'</td>';
							}
							if(column.className == 'executor'){
								newRow += '<td>'+info.executor+'</td>';
							}
							if(column.className == 'enquiryDate'){
								if(typeof(info.enquiryDate) == "undefined"){
									newRow += '<td></td>';
								}else{
									var date =new Date(info.enquiryDate);
									newRow += '<td>'+date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate()+'</td>';
								}
							}
							if(column.className == 'deliveryDate'){
								if(typeof(info. deliveryDate) == "undefined"){
									newRow += '<td></td>';
								}else{
									var date =new Date(info. deliveryDate);
									newRow += '<td>'+date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate()+'</td>';
								}
							}
							if(column.className == 'expirationDate'){
								newRow += '<td>'+info.expirationDate+'</td>';
							}
							if(column.className == 'remarks'){
								newRow += '<td>'+info.remarks+'</td>';
							}
							if(column.className == 'executor'){
								newRow += '<td>'+info.executor+'</td>';
							}
						});
						newRow += '</tr>';
						$("#productInfoTbody").append(newRow);
					});
				}
				pageNoOne = page.pageNo;
				pageSizeOne = page.pageSize;
				countOne = page.count;
				$("#clientelePageNo").html(pageNoOne);
				$("#clientelePageSize").html(pageSizeOne);
				$("#clienteleCount").html(countOne);
				$("#clienteleNextPageLi").attr("class","");
				if(pageNoOne <= 1){
					$("#clientelePreviousPageLi").attr("class","disabled");
				}
				if(pageNoOne >= countOne/pageSizeOne){
					$("#clienteleNextPageLi").attr("class","disabled");
				}
				$.jBox.close(selectJBox);
				//弹出选择框
				show();
			});
	 	}
	 });
</script>
</head>
<body class="fixed-top">
	<div class="container" style="width: 100%;">
		<div style="margin: 20px; border: 1px solid #c8d1d5;">
			<div id="see" class="hide">
				<div style="margin: 17px;">
					<div class="row-fluid"
						style="border: 1px solid #c8d1d5; padding-top: 10px; margin-bottom: 20px;">
						<div class="span3" style="margin-left: 10px; width: 30%">
							<label class="control-label"
								style="font-size: 14px; margin-bottom: 3px;">内部合同编号</label>
							<div class="">
								<input type="text" id="codes" readonly="readonly"
									class="span12" /> <input name=""
									id="virtualContractId" type="hidden" />
							</div>
						</div>
						<div class="span3">
							<label class="control-label"
								style="font-size: 14px; margin-bottom: 3px;">备注</label>
							<div>
								<input type="text" id="virtualContractRemarks"
									readonly="readonly"  />
							</div>
						</div>
					</div>
					<table id="conTable" class="table table-hover table-bordered">
						<thead>
							<tr class="widget-title">
								<c:forEach items="${columnList}" var="column">
									<c:choose>
										<c:when test="${column.className == 'productInfoName'}">
											<th style="white-space: normal;"><span
												id="productInfoNameSpan">产品名称</span></th>
										</c:when>
									</c:choose>
									<c:choose>
										<c:when test="${column.className == 'productInfoProductCode'}">
											<th style="white-space: normal;"><span
												id="productCodeSpan">产品代码</span></th>
										</c:when>
									</c:choose>
									<c:choose>
										<c:when
											test="${column.className == 'productInfoSpecifications'}">
											<th style="white-space: normal;"><span
												id="specificationsSpan">规格</span></th>
										</c:when>
									</c:choose>
									<c:choose>
										<c:when test="${column.className == 'productInfoBrand'}">
											<th style="white-space: normal;"><span id="brandSpan">品牌</span></th>
										</c:when>
									</c:choose>
									<c:choose>
										<c:when test="${column.className == 'productInfoPackaging'}">
											<th style="white-space: normal;"><span
												id="packagingSpan">封装</span></th>
										</c:when>
									</c:choose>
									<c:choose>
										<c:when test="${column.className == 'unitName'}">
											<th style="white-space: normal;"><span id="unitNameSpan">单位</span></th>
										</c:when>
									</c:choose>
									<c:choose>
										<c:when test="${column.className == 'supplierName'}">
											<th style="white-space: normal;"><span id="supplierNameSpan">供应商</span></th>
										</c:when>
									</c:choose>
									<c:choose>
										<c:when test="${column.className == 'noTaxPrice'}">
											<th style="white-space: normal;"><span
												id="noTaxPriceSpan">未税价格</span></th>
										</c:when>
									</c:choose>
									<c:choose>
										<c:when test="${column.className == 'taxPrice'}">
											<th style="white-space: normal;"><span id="taxPriceSpan">含税价格</span></th>
										</c:when>
									</c:choose>
									<c:choose>
										<c:when test="${column.className == 'count'}">
											<th style="white-space: normal;"><span id="countSpan">数量</span></th>
										</c:when>
									</c:choose>
									<c:choose>
										<c:when test="${column.className == 'brandReplace'}">
											<th style="white-space: normal;"><span
												id="brandReplaceSpan">品牌替代说明</span></th>
										</c:when>
									</c:choose>
									<c:choose>
										<c:when test="${column.className == 'abnormalProblem'}">
											<th style="white-space: normal;"><span
												id="abnormalProblemSpan">异常问题</span></th>
										</c:when>
									</c:choose>
									<c:choose>
										<c:when test="${column.className == 'executor'}">
											<th style="white-space: normal;"><span id="executorSpan">对应负责人</span></th>
										</c:when>
									</c:choose>
									<c:choose>
										<c:when test="${column.className == 'enquiryDate'}">
											<th style="white-space: normal;"><span
												id="enquiryDateSpan">询价日期</span></th>
										</c:when>
									</c:choose>
									<c:choose>
										<c:when test="${column.className == 'deliveryDate'}">
											<th style="white-space: normal;"><span
												id="deliveryDateSpan">送货日期</span></th>
										</c:when>
									</c:choose>
									<c:choose>
										<c:when test="${column.className == 'expirationDate'}">
											<th style="white-space: normal;"><span
												id="expirationDateSpan">保质期</span></th>
										</c:when>
									</c:choose>
									<c:choose>
										<c:when test="${column.className == 'affirmFlag'}">
											<th class="hidden-480"><span id="affirmFlagSpan">是否中标</span></th>
										</c:when>
									</c:choose>
									<c:choose>
										<c:when test="${column.className == 'remarks'}">
											<th class="hidden-480"><span id="remarksSpan">备注</span></th>
										</c:when>
									</c:choose>
								</c:forEach>
							</tr>
						</thead>
						<tbody id="productInfoTbody">
						</tbody>
					</table>
					<div class="pagination">
						<ul>
							<li id="clientelePreviousPageLi" class="disabled"><a
								id="clientelePreviousPage" href="javascript:">&#171;上一页</a></li>
							<li id="clienteleNextPageLi"><a id="clienteleNextPage"
								href="javascript:">下一页&#187;</a></li>
							<li class="disabled controls"><a>当前&nbsp; <span
									id="clientelePageNo"></span> / <span id="clientelePageSize"></span>
									条，共 <span id="clienteleCount"></span> 条
							</a></li>
						</ul>
					</div>
				</div>
			</div>
			<div style="padding: 13px; background-color: #f4f4f4; border-bottom: 1px solid #c8d1d5;">
				<h4>
					<i class="icon-globe"></i>内部合同管理
				</h4>
				<ul class="ul-form" style="float: right; margin-top: -25px;">
					<li style="list-style: none">
					<shiro:hasPermission name="pro:virtualDetail:edit">
						<a class="btn btn-primary"
							href="${ctx}/pro/virtualDetail/form?virtualContract.id=1"> <i
								class="icon-pencil"></i>&nbsp;新增
						</a> <a class="btn btn-danger" href="javascript:void(0)"
							onclick="deleteData()"> <i class="icon-trash"></i>&nbsp;删除
						</a> 
					</shiro:hasPermission>
				</li>
				</ul>
			</div>
			<div style="margin: 17px;">
				<form:form id="searchForm" modelAttribute="virtualContract"
					action="${ctx}/pro/virtualDetail/list" method="post"
					class="breadcrumb form-search">
					<input id="pageNo" name="pageNo" type="hidden"
						value="${page.pageNo}" />
					<input id="pageSize" name="pageSize" type="hidden"
						value="${page.pageSize}" />
					<ul class="ul-form">
					<li><label style="width: 150px;">合同订单编号：</label> <form:input path="codeNum"
								htmlEscape="false" maxlength="64" class="input-medium" /></li>
						<li><label>合同订单号：</label> <form:input path="code"
								htmlEscape="false" maxlength="64" class="input-medium" /></li>
						<li><label>日期：</label>&nbsp;<form:input id="beforeDate"
									path="beforeDate" readonly="true" maxlength="40" class="input-small Wdate"
									onclick="WdatePicker({dateFmt:'yyyy-MM-dd'});" />&nbsp; - &nbsp;<form:input id="rearDate"
									path="rearDate" readonly="true" maxlength="40" class="input-small Wdate"
									onclick="WdatePicker({dateFmt:'yyyy-MM-dd'});" /></li>
						<li class="btns"><a class="btn btn-primary"
							href="javascript:void(0)" onclick="return page();"><i
								class="icon-search"></i>&nbsp;搜索</a></li>
					</ul>
				</form:form>
				<sys:message content="${message}" />
				<table id="contentTable" class="table table-hover table-bordered" style="word-wrap:break-all;word-break:break-all;">
					<thead>
						<tr>
							<th style="width: 8px;"><input type="checkbox"
								class="group-checkable" id="checkAll" /></th>
							<th>内部合同编号</th>
							<th>内部合同订单号</th>
							<th>备注信息</th>
							<th>创建者</th>
							<th>制单时间</th>
							<shiro:hasPermission name="pro:virtualDetail:edit">
								<th>操作</th>
							</shiro:hasPermission>
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${page.list}" var="info">
							<tr>
								<td style="width: 8px;"><input type="checkbox" name="id"
									class="group-checkable" value="${info.id}" /></td>
								<td>${info.codeNum}</td>
								<td>${info.code}</td>
								<td>${info.remarks }</td>
								<td>${info.createBy.name}</td>
								<td><fmt:formatDate value="${info.createDate }"
										pattern="yyyy-MM-dd HH:mm:ss" /></td>
								<shiro:hasPermission name="pro:virtualDetail:edit">
									<td><a href="${ctx}/pro/virtualDetail/form?virtualContract.id=${info.id}"><i class="icon-edit"></i></a>
										<a href="${ctx}/pro/virtualDetail/deleteData?ids=${info.id}"
										onclick="return confirmx('确认要删除该吗？', this.href)"><i class="icon-remove"></i></a>
										<a href="javascript:" onclick="see(this)"><i class="icon-eye-open"></i></a>
										<input type="hidden" value="${info.id}"></td>
								</shiro:hasPermission>
							</tr>
						</c:forEach>
					</tbody>
				</table>
				<div class="pagination">${page}</div>
			</div>
		</div>
	</div>
</body>
</html>